package com.jd.basic.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;

public class SendEmailUtil {

    public static void sendEmail(String EmailCode,String email ,JavaMailSender javaMailSender){
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        try {
            // 2.发送复杂邮件的工具类
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "utf-8");
            helper.setFrom("2621512196@qq.com");
            helper.setSubject("测试复杂邮件");
            // 3.设置文本内容，第二个参数 true 代表是否是一个html内容
            helper.setText("<h1>邮箱注册验证码</h1>" +EmailCode
                    , true);
            // 4.添加附件
            helper.addAttachment("好东西.jpg", new File("E:\\feiqiu\\feiq\\RecvFace\\0bbfea4f.bmp"));
            // 5.设置收件人
            helper.setTo(email);
            // 6.发送邮件
            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }

}
